<template>
  <div id="app">
    <text-item :item="item" v-for="item of arr" :key="item._id"></text-item>
  </div>
</template>

<script>
/* 组件 */
import TextItem from '../../components/TextItem.vue' 
/* 得到传参值 */
import { getCurrentInstance } from '@tarojs/taro'

export default {
  data () {
    return {
      arr:[]
    }
  },
  components:{
    TextItem
  },
  mounted(){
    /* 获得传参值 */
    const id = getCurrentInstance().router.params.id
    this.$http(`/api/movieDetail?id=${id}`).then(res=>{
       var stat = res.data.res;
            var arr =[]
            stat.forEach(item=>{
                var {_id,title,pic,rating}=item;
                arr.push({
                    _id,title,pic,rating,rati:handleStat(rating)
                })
            })
            this.arr = arr
        });
        /* 星值评分 */
        function handleStat(num) {
        var arr=[]
        for(var i=0;i<5;i++){
            if(num>1.5){
                arr.push(2)
            }else if(num>0.5){
                arr.push(parseInt(num))
            }else{
                arr.push(0)
            }
            num-=2;
        }
        return arr
    }
  }

}
</script>

<style scoped>
*{
  padding: 0;
  margin: 0;
}
#app{
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
    
}
</style>
